﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Transactions;
using System.Runtime.Serialization;

using Unis.Framework.ORM.Attributes;
using Unis.Framework.RuleBase.Common;
using KingRoad.EPM.CompletionMaterialsEntity.Model;
using KingRoad.EPM.CompletionMaterialsDAL;
using System.Data;

namespace KingRoad.EPM.CompletionMaterialsDAL.BcdFileListService
{
    /// <summary> 
    /// 文件生成时间 2017/5/17 16:05:06
    /// </summary> 
    public class BcdFilelistService : BaseService<BcdFilelistInfo>, IBcdFilelistService
    {
        /// <summary>
        /// 根据条件获取最大档案流水号
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public int GetNumbBySql(string sql = "1=1")
        {
            int count = 0;
            string strSql = "select top(1) fl_numb from Bcd_FileList WHERE " + sql + " order by fl_numb desc  ";
            DataTable dt = DatabaseExcuteBySql.QuerybySql(strSql);
            if (dt.Rows.Count > 0)
            {
                string numb = dt.Rows[0][0].ToString();
                //System.Text.RegularExpressions.Regex rex = new System.Text.RegularExpressions.Regex(@"^\d+$");
                //if (rex.IsMatch(numb))
                count = Convert.ToInt32(numb);
            }
            return count;
        }

        /// <summary>
        /// 根据项目id，文档类型id 获取该项目此文档类型下案卷个数
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public int GetCountBySql(string sql)
        {
            string strSql = "select Count(Fl_ID) as numb from View_FileList where " + sql;
            DataTable dt = DatabaseExcuteBySql.QuerybySql(strSql);
            return Convert.ToInt32(dt.Rows[0][0]);
        }
        /// <summary>
        /// 插入案卷前操作 将已有案卷及之后案卷流水号+1
        /// </summary>
        /// <param name="Where"></param>
        /// <returns></returns>
        public int InsertNumb(string Where)
        {
            string _modelMapXmlName = "BcdFilelist";
            int ret = DatabaseExcuteByXmlHelper.NewInstance.ExecuteNonQuery(_modelMapXmlName, "InsertNumb", Where);
            return ret;
        }
    }

}

